package com.kehao.leetcode.middle.backtracking_algorithm;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class SubsetsSolution {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();
        getSubSets(nums,0,stack,result);
        return result;
    }

    private void getSubSets(int[] nums, int indexOfNum, Stack<Integer> stack, List<List<Integer>> result) {
        if(indexOfNum==nums.length){
            result.add(new ArrayList<>(stack));
        }else {
            getSubSets(nums,indexOfNum+1,stack,result);
            stack.push(nums[indexOfNum]);
            getSubSets(nums,indexOfNum+1,stack,result);
            stack.pop();
        }
    }

    @Test
    public void test01(){
        int[] nums = {1,2,3};
        System.out.println(subsets(nums));
    }
}
